package org.cfg;

import com.sojoys.artifact.build.data.base.BaseCfg;
import org.base.BaseGoods;
import com.sojoys.artifact.tools.ToolMap;
import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import org.constant.ItemType;
import com.sojoys.artifact.constant.DataModelKeyEnum;
/**
 * 时限道具
 */
public class ItemTimeCfg extends BaseCfg<ItemTimeCfg> implements org.base.BaseGoods{

	/**
	 * 数据库表名称
	 */
	public static final String TABLE_NAME = "item_time";
	/**
	 * 完整类名称
	 */
	public static final String CLASS_NAME = "org.cfg.ItemTimeCfg"; 
	/**
	 * 字段个数
	 */
	public static final int COLUMN_COUNT= 4;
	/**
	 * 数据库源字段注释
	 */
	public static final String[] SOURCE_COLUMN_REMARKS = new String[]{"","道具ID","限时类型","限时数值",};
	/**
	 * 数据库源字段名字
	 */
	public static final String[] SOURCE_COLUMN_NAMES = new String[]{"id","itemId","limitType","limitData",};
	/**
	 * 拼音字段名字
	 */
	public static final String[] PINGYING_COLUMN_NAMES = new String[]{"id","itemId","limitType","limitData",};
	/**
	 * HashCode字段名字
	 */
	public static final Integer[] HASHCODE_COLUMN_NAMES = new Integer[]{3355,-1178662002,1744370069,1743870469,};
	/**
	 * 字段基本类型
	 */
	public static final String[] COLUMN_BASICTYPES = new String[]{"int","int","int","int",};
	/**
	 * 字段引用类型
	 */
	public static final Class[] COLUMN_CLASSTYPES = new Class[]{Integer.class,Integer.class,Integer.class,Integer.class,};
	
	/**
	 * id
	 */
	private int id;
	
	/**
	 * 道具ID
	 */
	private int itemId;
	
	/**
	 * 限时类型
	 */
	private int limitType;
	
	/**
	 * 限时数值
	 */
	private int limitData;
	
	
	
	public static ItemTimeCfg builder() {
		ItemTimeCfg itemTimeCfg = new ItemTimeCfg();
		return itemTimeCfg;
	}
	
	/**
	 * id
	 */
	public int getId() {
		return id;
	}
	
	/**
	 * 道具ID
	 */
	public int getItemId() {
		return itemId;
	}
	
	/**
	 * 限时类型
	 */
	public int getLimitType() {
		return limitType;
	}
	
	/**
	 * 限时数值
	 */
	public int getLimitData() {
		return limitData;
	}
	
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		case REMARKS:
			return SOURCE_COLUMN_REMARKS;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.id;
        values[1] = this.itemId;
        values[2] = this.limitType;
        values[3] = this.limitData;
        return values;
	}
	
	protected ItemTimeCfg createColumeValues(Object[] vals) {
		this.id = (int)vals[0];
		this.itemId = (int)vals[1];
		this.limitType = (int)vals[2];
		this.limitData = (int)vals[3];
		return this;
	}
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map){
        map.put(keys[0], this.id);
        map.put(keys[1], this.itemId);
        map.put(keys[2], this.limitType);
        map.put(keys[3], this.limitData);
        return map;
    }
    
    protected ItemTimeCfg createForMap(Object[] keys,Map map){
   		this.id = (int)map.get(keys[0]);
   		this.itemId = (int)map.get(keys[1]);
   		this.limitType = (int)map.get(keys[2]);
   		this.limitData = (int)map.get(keys[3]);
        return this;
    }
	
	
	protected JSONObject toJSONObject(Object[] keys,JSONObject obj){
        obj.put(keys[0], this.id);
        obj.put(keys[1], this.itemId);
        obj.put(keys[2], this.limitType);
        obj.put(keys[3], this.limitData);
        return obj;
    }
    
    protected ItemTimeCfg createForJSONObject(Object[] keys,JSONObject obj){
	    this.id = obj.getIntValue(keys[0]);
	    this.itemId = obj.getIntValue(keys[1]);
	    this.limitType = obj.getIntValue(keys[2]);
	    this.limitData = obj.getIntValue(keys[3]);
        return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeInt(this.id);
	    byteBuf.writeInt(this.itemId);
	    byteBuf.writeInt(this.limitType);
	    byteBuf.writeInt(this.limitData);
    }
	
	protected ItemTimeCfg readBytes(IByteBuff byteBuf){
	    this.id = byteBuf.readInt(null);
	    this.itemId = byteBuf.readInt(null);
	    this.limitType = byteBuf.readInt(null);
	    this.limitData = byteBuf.readInt(null);
	    return this;
	}
	
	public ItemTimeCfg deepCopy(){
		ItemTimeCfg itemTimeCfg = null;
		try {
			itemTimeCfg = (ItemTimeCfg) super.clone();
			return itemTimeCfg;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return itemTimeCfg;
	}
//自定义内容起始位置
	BaseGoods goods = null;
	

	public BaseGoods getGoods() {
		return goods;
	}

	public void setGoods(BaseGoods goods) {
		this.goods = goods;
	}

	@Override
	public String getName() {
		return goods.getName();
	}

	@Override
	public int getNameTextId() {
		return goods.getNameTextId();
	}

	@Override
	public int getSuperType() {
		return goods.getSuperType();
	}

	@Override
	public int getSubType() {
		return goods.getSubType();
	}

	@Override
	public int getSmallType() {
		return goods.getSmallType();
	}

	@Override
	public int getBagType() {
		return goods.getBagType();
	}

	@Override
	public int getOrder() {
		return goods.getOrder();
	}

	@Override
	public int getStar() {
		return goods.getStar();
	}

	@Override
	public int getQuality() {
		return goods.getQuality();
	}

	@Override
	public Map getSellProfit() {
		return goods.getSellProfit();
	}

	@Override
	public Map getUseCast() {
		return goods.getUseCast();
	}

	@Override
	public Map getUseProfit() {
		return goods.getUseProfit();
	}

	@Override
	public int getTotalMax() {
		return goods.getTotalMax();
	}

	@Override
	public int getGridMax() {
		return goods.getGridMax();
	}

	@Override
	public Map getConvertMax() {
		return goods.getConvertMax();
	}

	@Override
	public int getOnceUseLimit() {
		return goods.getOnceUseLimit();
	}

	@Override
	public Map getDealProfit() {
		return goods.getDealProfit();
	}

	@Override
	public boolean getPileUp() {
		boolean pileUp = goods.getPileUp();
		// 如果是动态定时，则不能叠加
		pileUp &= (getLimitType() == ItemType.DYNAMIC_TIME_LIMIT ? false : true);
		return pileUp;
	}

	@Override
	public boolean getAutoUse() {
		return goods.getAutoUse();
	}
//自定义内容结束位置
}
